package com.example.listview;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class GoodsAdapter extends BaseAdapter {
    private GoodsList goodsList;

    public GoodsAdapter(GoodsList goodsList) {
        this.goodsList = goodsList;
    }
    @Override
    public int getCount() {
        return goodsList.getTitle().length;
    }
    @Override
    public Object getItem(int position) {
        return goodsList.getTitle()[position];
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null)
        {
            convertView = View.inflate(parent.getContext(),R.layout.item_layout,null);
            viewHolder = new ViewHolder();
            viewHolder.textView = convertView.findViewById(R.id.textView);
            viewHolder.textView3 = convertView.findViewById(R.id.textView3);
            viewHolder.image = convertView.findViewById(R.id.imageView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }

        viewHolder.textView.setText(goodsList.getTitle()[position]);
        viewHolder.textView3.setText(goodsList.getPra()[position]);
        viewHolder.image.setImageResource(goodsList.getText_id()[position]);
        return convertView;
    }
    private class ViewHolder
    {
        private TextView textView;
        private TextView textView3;
        private ImageView image;
    }
}
